﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LGCourt.Logic.Common;
using LGCourt.Logic.BLL;
using LGCourt.Logic.NBL.DBEntities;
using KMFrame.Permission.Util;

namespace lgweb.control.inside
{
    public partial class header : System.Web.UI.UserControl
    {
        public string TagIndex = "1";
        public string _DeptName1 = "";
        public string _DeptName2 = "";
        public string _DeptName3 = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                SetTagIndex();
                DateTime dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
                DateHandler dh = new DateHandler(dt);
                this.header_date.InnerHtml = "今天是" + DateTime.Now.ToLongDateString() + " 星期" + dh.weekValue + " 农历" + dh.lunarMonthValue + dh.lunarDayValue;
                GetUserInfo();

            }
        }

        private void SetTagIndex()
        {
            switch (this.TagIndex)
            {
                case "1":
                    this.hdindex.Attributes.Add("class", "current");
                    break;
                case "2":
                    this.hdoffice.Attributes.Add("class", "current");
                    break;
                case "3":
                    this.hdnews.Attributes.Add("class", "current");
                    break;
                case "4":
                    this.hdinfo.Attributes.Add("class", "current");
                    break;
                case "5":
                    this.hdwenhua.Attributes.Add("class", "current");
                    break;
                case "6":
                    this.hdshiping.Attributes.Add("class", "current");
                    break;
                case "7":
                    this.hdxuexi.Attributes.Add("class", "current");
                    break;
                default:
                    this.hdindex.Attributes.Add("class", "current");
                    break;
            }
        }

        private void GetUserInfo()
        {
            OA bll = new OA();
            vOAUser result = (vOAUser)bll.GetUserInfo(SessionBox.GetUserSession().UserID);

            if (result != null )
            {
                this.topDepart.InnerHtml = result.deptname;
                this.topUsername.InnerHtml = System.Web.HttpUtility.UrlDecode(Session["UserName"].ToString());//result.realname;
            }

            DepartmentHandler departmentHandler = new DepartmentHandler();
            List<Department> deptList = departmentHandler.GetDepartmentList();
            if (deptList != null)
            {
                List<Department> list1 = deptList.Where(a => a.RowIndex == 1).ToList();
                _DeptName3 = list1.FirstOrDefault().Name;
                _DeptName1 = list1.LastOrDefault().Name;
                this.rptDeptList1.DataSource = list1;
                this.rptDeptList1.DataBind();
                
                List<Department> list2 = deptList.Where(a => a.RowIndex == 2).ToList();
                _DeptName2 = list2.LastOrDefault().Name;
                this.rptDeptList2.DataSource = list2;
                this.rptDeptList2.DataBind();
                
            }
        }

        public string HandlerName(string Name)
        {
            string result = "";
            if (string.IsNullOrEmpty(Name))
                return result;
            result = Name;
            if (Name.Length == 2)
            {
                result = Name.Insert(1, " ");
            }
            if (Name.Length == 3)
            {
                result = Name.Insert(2, " ").Insert(1, " ");
            }
            //else if (Name.Length == 4)
            //{
            //    result = Name.Insert(4, " ").Insert(0, " ");
            //}
            //else
            //{

            //}


            return result;
        }
        public string HandlerSpace(string Name)
        {
            string result = "";
            
            if (Name.Length <= 4)
            {
                result = "&nbsp;";
            }
            if (Name == _DeptName3)
            {
                result = result + "&nbsp;";
            }
            if (Name != _DeptName1 && Name != _DeptName2)
            {
                result = result + "|";
            }
            return result;
        }

    }
}